<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <title>修改数组中的数据</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
</head>
<body>
    <div id="app">
        <button @click="addHobby">add hobby</button>
        <button @click="removeHobby">remove hobby</button>
        <ul>
            <li v-for="item in hobby" :key="item">{{ item }}</li>
        </ul>
    </div>

    <script>
        new Vue({
            el: '#app',
            data: {
                hobby: ['抽烟', '喝酒', '烫头']
            },
            methods: {
                addHobby() {
                    // this.hobby[3] = '篮球'
                    // this.$set(this.hobby, 3, '篮球')
                    this.hobby.push('篮球')
                },
                removeHobby() {
                    // this.hobby[0] = null
                    // this.$set(this.hobby, 0, undefined)
                    this.hobby.shift()
                }
            }
        })
    </script>
</body>
</html>